package homework;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

public class UserDao {
    public void insert(User user) throws Exception {
        Class.forName("com.mysql.jdbc.Driver");

        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/db2", "root", "root");

        PreparedStatement ps = con.prepareStatement("insert into stu(id,name,password) values (?,?,?)");

        ps.setInt(1,user.getId());
        ps.setString(2,user.getName());
        ps.setString(3, user.getPwd());

        ps.executeUpdate();
    }
}
